<?php

class ContactController extends Controller
{
	public function actionIndex()
	{
		$this->render('index');
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
	
	public function actionMail() {
		if (isset($_POST)) {
			//echo '===========';
			//exit;
			
			$contact = new Contact();
			
			$contact->name = isset($_POST['name'])?$_POST['name']:'';
			$contact->email = isset($_POST['email'])?$_POST['email']:'';
			$contact->message = isset($_POST['comments'])?$_POST['comments']:'';
			
			if ($contact->save()) {
				
				$mail=Yii::app()->Smtpmail;
		        $mail->SetFrom('testmailnoreply2@gmail.com', 'testmailnoreply');
		        $mail->Subject    = 'From Tattoo';
		        $mail->MsgHTML($contact->message);
		        $mail->AddAddress($contact->email, $contact->name);
		        if(!$mail->Send()) {
		            echo "Mailer Error: " . $mail->ErrorInfo;
		            exit;
		        }else {
		            //echo "Message sent!";
		            $this->redirect('/#section5');
		        }
		        
			}
			
		}
	}
}